package cn.sc.summer.redis.config;

import cn.sc.summer.constant.redis.RedisConstant;
import cn.sc.summer.redis.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.Resource;

/**
 * 类名：redis配置类
 *
 * @author a-xin
 * @date 2023/8/11 19:47
 */
@Slf4j
@Configuration
public class RedisConfig {

    @Resource
    private RedisConnectionFactory redisConnectionFactory;

    @Bean(value = RedisConstant.REDIS_BEAN_NAME)
    public RedisTemplate<String, Object> redisCacheTemplate() {
        log.info("==> Start config the Redis serialization mode......");
        //为了开发的方便，一般直接使用<String, Object>
        RedisTemplate<String, Object> template = new RedisTemplate<>();
        RedisUtil.initRedisTemplate(template, redisConnectionFactory);
        log.info("==> Redis connection succeeded！ Redis serialization succeeded！");
        return template;
    }

}
